class UserController < ApplicationController
	layout 'standard' 
	# list returns the information needed for user/list.rhtml
	def list
		@event = Event.find(params[:id])
			
		@user = User.find(:all, :conditions => ["event_id = ?", params[:id]])
	end
	# show is called for each item in @users in user/list.rhtml
	def show
		@user = User.find(params[:id])
	end
	
	# new returns the information needed for user/new.rhtml
	def new
		@user = User.new
		@event = Event.find(params[:id])
	end
	# create is called when someone clicks the Create button on user/new.rhtml
	def create
		@user = User.new(params[:user])
		@event = Event.find(params[:id])
		
		@user[:event_id] = @event.id
		
		if @user.save
			redirect_to :action => 'free', :uid => @user.id, :id => @event.id
		else
			# replace this with an error
			redirect_to :action => 'error'
		end
	end
	
	# free returns the information needed for user/free.rhtml
	def free
		@frees = Free.find(:all)
		@user = User.find(params[:uid])
		@event = Event.find(params[:id])
	end
	# submit is called when someone clicks the Submit button on user/free.rhtml
	def submit
		@frees = Free.find(:all)
		@user = User.find(params[:uid])
		@event = Event.find(params[:id])
		redirect_to :controller => 'user', :action => 'new', :id => @event.id
	end
	
	# edit returns the information needed for user/edit.rhtml
	def edit
		@event = Event.find(params[:id])
		@times = Free.find(:all)
	end
	# update is called when someone clicks the Update button on user/edit.rhtml
	def update
	end
	
	# delete will remove the user
	def delete
	end
	
	def signup
		case request.method
			when :post
				@user = User.new(params[:user])
				if @user.save
					redirect_to :controller => 'user', :action => 'list'
				end
		end
	end
	
	def login
		if session[:user] = User.authenticate(params[:login], params[:password]) 
			redirect_to :controller => 'user', :action => 'list'
		else
			redirect_to :controller => 'user', :action => 'list'
		end
	end
	
	def logout
		reset_session
		redirect_to :controller => 'user', :action => 'list'
	end
	
	
end
